// 引入vuex 的API
import {createStore} from "vuex"

// 引入模块
import moduleA from "./modules/moduleA"
import moduleB from "./modules/moduleB"

// 创建一个实例化的vuex对象并抛出
export default createStore({
    modules:{
        a:moduleA,
        b:moduleB
    },
    state:{
        count:5,
        test:'hello world'
    },
    getters:{
        countAddFive:(state) => {
            return state.count + 5
        },
        countAddFiveAddTen:(state,getters) => {
            return getters.countAddFive + 10
        }
    },
    mutations:{
        add(state){
            state.count++
        },
        addPlayload(state, playload){
            state.count += playload.num // a +=b ----->>> a= a +b 
        }
    },
    actions:{
        // addAction(context){ // context ===>> state, commit,xxxx
        //     context.commit('add')
        // },
        addAction({commit}){ // context ===>> state, commit,xxxx
            commit('add')
        },
        asyncAddAction({commit}){
            setTimeout(()=>{
                commit('add')
            },1000)
        },
        asyncAddPloyloadAction({commit}, playload){
            setTimeout(()=>{
                commit('addPlayload', playload)
            },1000)
        }
    }
})